﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using WorkSummary.Bussiness.Bll;
using WorkSummary.Bussiness.Model;
using WorkSummary.Common;

namespace WorkSummaryReoprter.ashx
{
    /// <summary>
    /// User 的摘要说明
    /// </summary>
    public class User : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var action = context.Request["action"];
            var json = context.Request["json"];
            switch (action)
            {
                case "ChangePwd":
                    var new_pwd = context.Request["new_pwd"];
                    var old_pwd = context.Request["old_pwd"];
                    context.Response.Write(JSONhelper.ToJson(BUser.Instance.ChangePwd(old_pwd,new_pwd)));
                    break;
                case "forgetpwd":
                    context.Response.Write(JSONhelper.ToJson(""));
                    break;
                case "GetAllUser":
                    var username = context.Request["username"];
                    context.Response.Write(JSONhelper.ToJson(BUser.Instance.GetAllUser(username)));
                    break;
                case "AddUser":
                    MUser muser = JSONhelper.ConvertToObject<MUser>(json);
                    context.Response.Write(JSONhelper.ToJson(BUser.Instance.AddUser(muser)));
                    break;
                case "ModifyUser":
                    MUser muser1 = JSONhelper.ConvertToObject<MUser>(json);
                    context.Response.Write(JSONhelper.ToJson(BUser.Instance.ModifyUser(muser1)));
                    break;
                case "DelUser":
                    var IDs = context.Request["IDs"];
                    context.Response.Write(JSONhelper.ToJson(BUser.Instance.DelUser(IDs)));
                    break;
                default:
                    context.Response.Write(JSONhelper.ToJson(new { code = -1, msg = "no action matched！" }));
                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}